package com.sxt.copy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class Jsoup2 {
	public static List<String> list;
	
	public static List<String> addArticle(String URL,String titleCss,String contentCss){
		
		  
			Document doc;
			try {
				doc = Jsoup.connect(URL).get();
				Elements t = doc.select(titleCss);
				Elements c = doc.select(contentCss);
			    String title = t.text();
			    String content = c.toString();
			    //替换图片路径
			
			    list = new ArrayList<String>();
			    list.add(title);
			    list.add(content);
			} catch (IOException e) {
			
				e.printStackTrace();
			}
			
		return list;

		        }	 
	/*public static String getContent(Elements c){
		
		String content0 = c.toString().replace("</p>", "Gakkiyomi");
	    String htmlStr = content0;
        String content = "";
        java.util.regex.Pattern p_script;
        java.util.regex.Matcher m_script;
        java.util.regex.Pattern p_style;
        java.util.regex.Matcher m_style;
        java.util.regex.Pattern p_html;
        java.util.regex.Matcher m_html;
        java.util.regex.Pattern p_html1;
        java.util.regex.Matcher m_html1;
        
        String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; 
        String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
        String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
        String regEx_html1 = "<[^>]+";
        String regEx_kg = "\\s";
        p_script = Pattern.compile(regEx_script,
                Pattern.CASE_INSENSITIVE);
        m_script = p_script.matcher(htmlStr);
        htmlStr = m_script.replaceAll(""); // 过滤script标签
        p_style = Pattern
                .compile(regEx_style, Pattern.CASE_INSENSITIVE);
        m_style = p_style.matcher(htmlStr);
        htmlStr = m_style.replaceAll(""); // 过滤style标签
        p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
        m_html = p_html.matcher(htmlStr);
        htmlStr = m_html.replaceAll(""); // 过滤html标签
        p_html1 = Pattern
                .compile(regEx_html1, Pattern.CASE_INSENSITIVE);
        m_html1 = p_html1.matcher(htmlStr);
        htmlStr = m_html1.replaceAll(""); // 过滤html标签
       
        //htmlStr = htmlStr.replaceAll("",regEx_kg); // 过滤空格
        htmlStr = htmlStr.replaceAll("\\s",""); 
        
        content = htmlStr.replace("Gakkiyomi", "\r\n");
		return content;
		
	}*/
		   }
